package com.ryder.auth.domain.service.impl;

import com.ryder.auth.common.enums.IsDeleteFlagEnum;
import com.ryder.auth.domain.entity.AuthRolePermissionBO;
import com.ryder.auth.domain.service.AuthRolePermissionDomainService;
import com.ryder.auth.infra.basic.entity.AuthRolePermission;
import com.ryder.auth.infra.basic.service.AuthRolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

/**
 * 描述: (AuthRolePermission)表服务实现类
 * 
 * @author Ryder
 * @version 1.0
 * @since 1.0 // 版本号，指明从哪个版本开始
 * 更新日期: 2025-02-18 02:31:15
 */
@Service
public class AuthRolePermissionDomainServiceImpl implements AuthRolePermissionDomainService {
    @Autowired
    private AuthRolePermissionService authRolePermissionService;

    @Override
    public Boolean add(AuthRolePermissionBO authRolePermissionBO) {
        List<AuthRolePermission> rolePermissionList = new LinkedList<>();
        Long roleId = authRolePermissionBO.getRoleId();
        authRolePermissionBO.getPermissionIdList().forEach(permissionId -> {
            AuthRolePermission authRolePermission = new AuthRolePermission();
            authRolePermission.setRoleId(roleId);
            authRolePermission.setPermissionId(permissionId);
            authRolePermission.setIsDeleted(IsDeleteFlagEnum.UN_DELETED.getCode());
            rolePermissionList.add(authRolePermission);
        });
        int count = authRolePermissionService.insertBatch(rolePermissionList);
        return count > 0;
    }
}
